package inet.app.controller.parser;

import inet.app.model.object.KqGiai_Item;

import java.util.ArrayList;
public class Parser_Cau {



	private String NAME = "TKCAU_RESP";
	private ArrayList<KqGiai_Item> list = new ArrayList<KqGiai_Item>();
	
	public Parser_Cau() {
	}
	
	public ArrayList<KqGiai_Item> getList(String json) {
		
		String[] data = json.split("\\|\\|\r\n");
		System.out.println("DATA SIZE " + data.length);
		String[] item_first = data[0].split("\\|");
		
		String name = item_first[0];
		
		String status = item_first[1];
		if (status.equals("0") && name.equals(NAME)) {
			int i = 0;
			KqGiai_Item item;
			String kqgiai[] ;
			String last_update, code,date,dacbiet= null, giai1 = null, giai2= null,giai3= null,giai4 = null,giai5= null,giai6= null,giai7= null,giai8= null;
			for (i = 0; i < data.length; i++) {
				kqgiai = data[i].split("\\|");
				last_update= kqgiai[2];
				code = kqgiai[3];
				String[] temp;
				temp= kqgiai[4].split(" ");
//				date = kqgiai[4];
				date = temp[0];
				
				for (int j = 5; j < kqgiai.length; j++) {
					if(kqgiai[j].substring(0,1).equals("0")) dacbiet = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("1")) giai1 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("2")) giai2 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("3")) giai3 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("4")) giai4 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("5")) giai5 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("6")) giai6 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("7")) giai7 = kqgiai[j];
					else giai8 = kqgiai[j];
				}
				item = new KqGiai_Item(last_update,code, date, dacbiet, giai1, giai2, giai3, giai4, giai5, giai6, giai7,giai8);
				list.add(item);
			}
			return list;
		} else
			return null;
	}

public String getString(String json) {
		String _result = null;
		String[] data = json.split("\\|\\|\r\n");
		System.out.println("DATA SIZE " + data.length);
		String[] item_first = data[0].split("\\|");
		
		String name = item_first[0];
		
		String status = item_first[1];
		if (status.equals("0") && name.equals(NAME)) {
			return json;
		} else
			return null;
	}


}
